package com.zhuiYun.project.api.seckill.mapper;

import com.zhuiYun.project.api.seckill.entity.SeckillEntity;
import com.zhuiYun.project.common.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

/**
 * @ClassName SeckillServiceImpl
 * @Description TODO
 * @Author lx
 * @Date 2023/4/3 15:00
 **/
public interface SeckillMapper extends BaseMapper<SeckillEntity> {

    @Update("update seckill set seckill_stock = #{seckillStock} WHERE comm_id = #{id}")
    void update(SeckillEntity seckill);

    /**
    * @Description // 查询是否是秒杀商品
    * @Author lzy
    * @Date 2023/4/12 19:41
    * @Return java.lang.Integer
    * @param id
    */
    @Select("select * from seckill where comm_id = #{id}")
    SeckillEntity selectInventory(Integer id);

    /**
    * @Description 秒杀表减库存
    * @Author lzy
    * @Date 2023/4/12 19:51
    * @Return java.lang.Integer
    * @param id
    * @param number
    */
    @Update("update seckill set seckill_stock = seckill_stock - #{number} where comm_id = #{id}")
    Integer reduceInventory(@Param("id") Integer id, @Param("number") Integer number);

    /**
    * @Description 秒杀表回滚库存
    * @Author lzy
    * @Date 2023/4/13 8:15
    * @Return java.lang.Integer
    * @param commodityId
    * @param commodityQuantity
    */
    @Update("update seckill set seckill_stock = seckill_stock + #{number} where comm_id = #{id}")
    Integer rollBackInventory(@Param("id") Integer commodityId,@Param("number") Integer commodityQuantity);
}
